﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using HiStaff.Domain.Sys;
using HiStaff.Dal;
using System.Data;

namespace HiStaff.Service
{
    public partial class System : ISystem
    {
        #region system
        /// <summary>
        /// Get all table in user database
        /// </summary>
        /// <returns></returns>
        public List<ALL_TABLE> GetAllTable()
        {
            return OracleHelper.ExcuteSelectMultiObject<ALL_TABLE>("PKG_SYSTEM", "PRS_ALL_TABLE");
        }
        /// <summary>
        /// Get all data list in system
        /// </summary>
        /// <returns></returns>
        public List<SY_TAB_LIST> GetAllDataList()
        {
            return OracleHelper.ExcuteSelectMultiObject<SY_TAB_LIST>("APRS_SY_TAB_LIST");
        }
        public List<SY_TAB_LIST> GetDataListByUser(string userName)
        {
            return OracleHelper.ExcuteSelectMultiObject<SY_TAB_LIST>("APRS_SY_TAB_LIST", new SY_TAB_LIST { USERNAME = userName });
        }
        public List<SY_COLUMNS_LIST> GetColumnList(string tableName)
        {
            return OracleHelper.ExcuteSelectMultiObject<SY_COLUMNS_LIST>("APRS_SY_COLUMNS_LIST", new SY_COLUMNS_LIST { TABLE_NAME = tableName });
        }
        public List<SY_DEFAULT_LIST> GetDataListReturnDefault(string procname)
        {
            return OracleHelper.ExcuteSelectMultiObject<SY_DEFAULT_LIST>(procname);
        }
        public List<SY_DATA_TYPE> GetDataType()
        {
            return OracleHelper.ExcuteSelectMultiObject<SY_DATA_TYPE>("APRS_SY_DATA_TYPE");
        }
        public List<SY_COMPARE_TYPE> GetCompareType()
        {
            return OracleHelper.ExcuteSelectMultiObject<SY_COMPARE_TYPE>("APRS_SY_COMPARE_TYPE");
        }

        #endregion
        #region sy_user
        public List<SY_USER> GetUser(SY_USER arg)
        {
            return OracleHelper.ExcuteSelectMultiObject<SY_USER>("APRS_SY_USER", arg);
        }

        public bool UpdateUser(SY_USER arg)
        {
            return OracleHelper.ExcuteNonQuery("APRU_SY_USER", arg);
        }

        public bool DeleteUser(SY_USER arg)
        {
            return OracleHelper.ExcuteNonQuery("APRD_SY_USER", arg);
        }
        #endregion
        #region sy_function && sy_module
        public List<SY_FUNCTION> GetFunction(SY_FUNCTION arg)
        {
            return OracleHelper.ExcuteSelectMultiObject<SY_FUNCTION>("APRS_SY_FUNCTION", arg);
        }
        public List<SY_MODULE> GetModule(SY_MODULE arg)
        {
            return OracleHelper.ExcuteSelectMultiObject<SY_MODULE>("APRS_SY_MODULE", arg);
        }
        public List<SY_FUNC_TYPE> GetFunctionType()
        {
            return OracleHelper.ExcuteSelectMultiObject<SY_FUNC_TYPE>("APRS_SY_FUNC_TYPE");
        }
        #endregion

        #region save data list
        public bool SaveTableList(SY_TAB_LIST parameter)
        {
            return OracleHelper.ExcuteNonQuery("APRU_SY_TAB_LIST", parameter);
        }
        public bool SaveColumnsList(DataTable parameter)
        {
            try
            {
                foreach (var dr in parameter.Rows)
                {
                    OracleHelper.ExcuteNonQuery("APRU_SY_COLUMNS_LIST", dr);
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool CreateTableDataList(string tableName)
        {
            return OracleHelper.ExcuteNonQuery("PKG_SYSTEM", "PRC_TABLE_LIST", new SY_TAB_LIST { TABLE_NAME = tableName });
        }
        public bool CreateUpdateStore(string tableName)
        {
            return OracleHelper.ExcuteNonQuery("PKG_SYSTEM", "PRC_PROCEDURE_UPDATE", new SY_TAB_LIST { TABLE_NAME = tableName });
        }
        public bool CreateDeleteStore(string tableName)
        {
            return OracleHelper.ExcuteNonQuery("PKG_SYSTEM", "PRC_PROCEDURE_DELETE", new SY_TAB_LIST { TABLE_NAME = tableName });
        }
        public bool CreateSelectStore(string tableName)
        {
            return OracleHelper.ExcuteNonQuery("PKG_SYSTEM", "PRC_PROCEDURE_SELECT", new SY_TAB_LIST { TABLE_NAME = tableName });
        }
        #endregion
        #region data list
        
        #endregion
    }
}
